﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace GestionEducativa.DataLayer
{
    public class RolRepository
    {
        Gestion_EducativaEntities ObjectContext = new Gestion_EducativaEntities();
        public void InsertarRol(Rol r)
        {
            ObjectContext.AddToRol(r);
            ObjectContext.SaveChanges();
        }

        public void BorrarRol(string rl)
        {
            Rol r = (from rx in ObjectContext.Rol where rx.rol == rl select rx).First();
            ObjectContext.Rol.DeleteObject(r);
            ObjectContext.SaveChanges();
        }

        public void ActualizarRol(string rl1, string rl2)
        {
            Rol r = (from rx in ObjectContext.Rol where rx.rol == rl1 select rx).First();
            r.rol = rl2;
            ObjectContext.SaveChanges();
        }

        public Rol TraerRol(string rl)
        {
            Rol r = (from rx in ObjectContext.Rol where rx.rol == rl select rx).First();
            return r;
        }

        public IEnumerable<Rol> TraerTodosRol()
        {
            IEnumerable<Rol> rlist = (from rx in ObjectContext.Rol select rx).AsEnumerable();
            return rlist;
        }
    }
}